import java.util.Random;
import java.util.Scanner;
import java.text.NumberFormat;

public class ArithmeticDevice {

    public static void main(String[] args) {
        int d1 = 0, answer;
        int x;

        Scanner scan = new Scanner(System.in);

        Random num1 = new Random();
        Random num2 = new Random();
        Random operation = new Random();

        System.out.println("Please enter the number of test you want:");
        Scanner scan1 = new Scanner(System.in);
        x = scan1.nextInt();

        int j = 1;
        double m = 0.0 , n = 0.0 ;
        double accuracy;

        for (int i = 0; i < x; i++) {

            System.out.println("Equation" + j);

            //随机生成a、b两个1-10的整数

            int a = num1.nextInt(10) + 1;
            int b = num2.nextInt(10) + 1;

            //随机生成一个0-3的整数，0代表加法，1代表减法，2代表乘法，3代表除法

            int c = operation.nextInt(4);

            switch (c) {
                case 0:
                    d1 = a + b;
                    System.out.println(a + "+" + b + "=  ");
                    break;
                case 1:
                    d1 = a - b;
                    System.out.println(a + "-" + b + "=  ");
                    break;
                case 2:
                    d1 = a * b;
                    System.out.println(a + "×" + b + "=  ");
                    break;
                case 3:
                    d1 = a / b;
                    System.out.println(a + "÷" + b + "=  ");
                    break;

            }
            //用户根据指令输入答案，判断答案是否正确

            answer = scan.nextInt();

            if (answer == d1){
                System.out.println("Great!Your answer is right.");
                m++;
                System.out.println(m);
            }
            else {
                System.out.println("Sorry.Your answer is not right, the right answer is " + d1);
                n++;
                System.out.println(n);
            }
            j++;

        }
        //计算正确率，并让正确率以百分数的形式输出

        accuracy = m / ( m + n );
        NumberFormat percent = NumberFormat.getPercentInstance();
        percent.setMinimumFractionDigits(2);

        System.out.println("Your accuracy is: " + percent.format(accuracy) );

    }
}